package com.middlegroup.payadmin.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.middlegroup.payadmin.mapper.LogMapper;
import com.middlegroup.payadmin.pojo.dto.DataGrid;
import com.middlegroup.payadmin.pojo.po.Log;
import com.middlegroup.payadmin.service.LogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author pc
 */
@Service
public class LogServiceImpl extends ServiceImpl<LogMapper,Log> implements LogService {

    @Resource
    private LogMapper logMapper;


    @Override
    public PageInfo<Log> listForDataGrid(DataGrid grid, String datetime) {

        grid.getOrderBy();
        EntityWrapper<Log> ew = new EntityWrapper<Log>();
        String startTime, endTime;
        if (StringUtils.isNotEmpty(datetime)) {
            String[] time = datetime.split(" - ");
            startTime = time[0];
            endTime = time[1];
            ew.where("gmt_create between {0} and {1}",startTime,endTime);
        }
        return PageHelper.startPage(grid.getPageNum(), grid.getPageSize()).doSelectPageInfo(() -> this.logMapper.selectList(ew));
    }

    @Override
    public List<Log> listAll() {
        return logMapper.selectList(null);
    }
}
